import pyautogui
import cv2
from PIL import Image
import numpy as np

def capture_captcha_manual(save_path="captcha.png"):
    print("请用鼠标拖动选择验证码区域...")
    screenshot = pyautogui.screenshot()  # 截全屏
    screenshot_cv = cv2.cvtColor(
        np.array(screenshot), cv2.COLOR_RGB2BGR
    )  # 转为OpenCV格式

    # 手动选择区域
    roi = cv2.selectROI("Select Captcha Area", screenshot_cv, fromCenter=False)
    cv2.destroyAllWindows()

    if roi != (0, 0, 0, 0):
        x, y, w, h = roi
        captcha = screenshot.crop((x, y, x + w, y + h))
        captcha.save(save_path)
        print(f"验证码已保存到: {save_path}")
        return captcha
    else:
        print("未选择区域！")

def get_capture_image():
    pass


import os
import dotenv  # type: ignore

from llm import AliQwen, DeepSeek, DouBao, Kimi
from capture import get_capture_image


class DotEnv:
    def __init__(self):
        self.__DeepSeek = os.getenv("DeepSeekKey")
        self.__DouBao = os.getenv("DouBaoKey")
        self.__AliQwen = os.getenv("AliQwenKey")
        self.__Kimi = os.getenv("KimiKey")

    def get_deep_seek(self):
        return self.__DeepSeek

    def get_dou_bao(self):
        return self.__DouBao

    def get_ali_qwen(self):
        return self.__AliQwen

    def get_kimi(self):
        return self.__Kimi


def load_env():
    dotenv.load_dotenv()
    keys = dotenv.dotenv_values()
    return keys


def load_llm_model(keys):
    deepseek = DeepSeek(keys.get_deep_seek())
    doubao = DouBao(keys.get_dou_bao())
    aliqwen = AliQwen(keys.get_ali_qwen())
    kimi = Kimi(keys.get_kimi())
    image = get_capture_image()

    if deepseek is not None:
        return DeepSeek(deepseek)
    if doubao is not None:
        return DouBao(doubao)
    if aliqwen is not None:
        return AliQwen(aliqwen)
    if kimi is not None:
        return Kimi(kimi)


def main():
    load_env()
    keys = DotEnv()
    model = load_llm_model(keys)
    if model is None:
        print("No model found, please set api key ")
    else:
        model.run()





if __name__ == "__main__":
    main()

